package main

import (
	"flag"
	"fmt"
	"os"
	"os/exec"
)

func mainExec() {
	fs := flag.NewFlagSet("exec", flag.ExitOnError)
	fs.Parse(os.Args[2:])
	if fs.NArg() == 0 {
		fmt.Fprintln(os.Stderr, "usage: vm exec <pid> CMD args...")
		os.Exit(1)
	}

	cmd := exec.Command("/proc/self/exe")
	args := fs.Args()
	cmd.Args = []string{cmd.Path, "_exec", "-pid", args[0]} // TODO: add -w param
	cmd.Args = append(cmd.Args, args[1:]...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	assert(cmd.Run())
}
